package com.tomehay.termprojectmanage_server.controller;


import com.tomehay.termprojectmanage_server.pojo.DTO.StudentGroupDTO;
import com.tomehay.termprojectmanage_server.pojo.Model.Student;
import com.tomehay.termprojectmanage_server.pojo.VO.GroupMembersVO;
import com.tomehay.termprojectmanage_server.pojo.VO.ResultVO;
import com.tomehay.termprojectmanage_server.service.StudentGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tomehay
 * @since 2023-06-20
 */
@RestController
@RequestMapping("api/studentGroup")
public class StudentGroupController {

    @Autowired
    StudentGroupService studentGroupService;
    @GetMapping("/GetGroupsByCourseId")
    public ResultVO<List<GroupMembersVO>> GetGroupsByCourseId(@RequestParam(value = "course_id") int courseId, int batch_id){
        return studentGroupService.GetGroupsByCourseId(courseId,batch_id);
    }

    @GetMapping("/GetGroupsById")
    public ResultVO<GroupMembersVO> GetGroupsById(@RequestParam(value = "id") int id){
        return studentGroupService.GetGroupsById(id);
    }

    @GetMapping("/GetBatches")
    public ResultVO<int[]> GetBatches(){
        return studentGroupService.GetBatches();
    }

    @GetMapping("/SelectUnGrouped")
    public ResultVO<List<Student>> SelectUnGrouped(int course_id,int batch_id){
        return studentGroupService.SelectUnGrouped(course_id,batch_id);
    }

    @PostMapping("/CreateStudentGroup")
    public ResultVO<Void> CreateStudentGroup(@RequestBody StudentGroupDTO studentGroupDTO){
        return studentGroupService.CreateStudentGroup(studentGroupDTO.getStudents()
                ,studentGroupDTO.getBatch_id()
                ,studentGroupDTO.getCourse_id()
                ,studentGroupDTO.getLeader_id());
    }

    @DeleteMapping("/DeleteStudentGroup")
    public ResultVO<Void> DeleteStudentGroup(int GroupId){
        return studentGroupService.DeleteStudentGroup(GroupId);
    }
}
